<?php
if (! defined ( 'BASEPATH' ))
	exit ( 'No direct script access allowed' );


/**
 * get all languages
 *
 * @param
 *        	string	language
 * @return language
 */
if (! function_exists ( 'get_all_languages' )) {
	function get_all_languages() {
		$languages = array('zh','en');
		return $languages;
	}
}

/**
 * get the language
 *
 * @param
 *        	string	language
 * @return language
 */
if (! function_exists ( 'get_language' )) {
	function get_language($str) {
		switch ($str) {
			case 'zh-cn' :
				$language = 'zh';
				break;
			default :
				$language = 'en';
				break;
		}
		return $language;
	}
}



/**
 * get the language dir
 *
 * @param
 *        	string	language
 * @return language
 */
if (! function_exists ( 'get_language_full' )) {
	function get_language_full($str) {
		switch ($str) {
			case 'zh' :
				$language = 'zh-cn';
				break;
			default :
				$language = 'english';
				break;
		}
		return $language;
	}
}

/**
 * get the local
 *
 * @param
 *        	string	language
 * @return language
 */
if (! function_exists ( 'get_local' )) {
	function get_local() {
		$ci = &get_instance();
		$ci->load->helper('cookie');
		
		if(in_array(get_cookie('set_language') ,get_all_languages())){
			return get_cookie('set_language');
		}
		
		$onlineip = $ci->input->ip_address();
		$localinfo = @file_get_contents ( 'http://api.ipinfodb.com/v3/ip-country?key=fc507f53762b0be48618db99d4a2483ccfbe4a618c5d73f6258b48e20bf0c7ad&ip=' . $onlineip );
		$local = end ( explode ( ';', $localinfo ) );
		switch ($local) {
			case 'CHINA' :
				return 'zh';
			default :
				return 'en';
		}
	}
}